Enabling DataDirect Spy™
You can enable DataDirect Spy for a connection using any of the following methods:
- Specifying the SpyAttributes connection property for connections using the JDBC Driver Manager. See "Using the JDBC Driver Manager" for instructions.
- Specifying DataDirect Spy attributes using a JDBC data source. See "Using JDBC Data Sources" for instructions.
- Specifying a DataDirect Spy-specific connection URL. See "Using the DataDirect Spy™ URL" for instructions. If you use this method to enable DataDirect Spy, you first must register the DataDirect Spy driver.
Using any of these methods, you can set one or multiple options to customize DataDirect Spy logging. See "DataDirect Spy™ Attributes" for a complete list of supported attributes.
Using the JDBC Driver Manager
The SpyAttributes connection property allows you to specify a semi-colon separated list of DataDirect Spy attributes (see "DataDirect Spy™ Attributes"). The format for the value of the SpyAttributes property is:
where
spy_attributeis any valid DataDirect Spy attribute. See "DataDirect Spy™ Attributes" for a list of supported attributes.Example on Windows:
The following example uses the JDBC Driver Manager to connect to Oracle while enabling DataDirect Spy:
Class.forName("com.ddtek.jdbc.sequelink.SequeLinkDriver"); Connection conn = DriverManager.getConnection ("jdbc:sequelink://QANT:4003;user=TEST;password=secret; SpyAttributes=(log=(file)C:\\temp\\spy.log; linelimit=80;logTName=yes;timestamp=yes)");Using this example, DataDirect Spy would load the SequeLink for JDBC driver and log all JDBC activity to the spy.log file located in the C:\temp directory (
log=(file)C:\temp\spy.log). The spy.log file logs a maximum of 80 characters on each line (linelimit=80) and includes the name of the current thread (logTName=yes) and a timestamp on each line in the log (timestamp=yes).NOTE: If coding a path on Windows to the log file in a Java string, the backslash character (\) must be preceded by the Java escape character, a backslash. For example: log=(file)C:\\temp\\spy.log.
Example on Linix and UNIX:
The following code example uses the JDBC Driver Manager to connect to DB2 while enabling DataDirect Spy:
Class.forName("com.ddtek.jdbc.sequelink.SequeLinkDriver"); Connection conn = DriverManager.getConnection ("jdbc:sequelink://user=TEST;password=secret; SpyAttributes=(log=(file)C:\\temp\\spy.log; linelimit=80;logTName=yes;timestamp=yes)");Using this example, DataDirect Spy would load the DataDirect SequeLink driver and log all JDBC activity to the spy.log file located in the /tmp directory (
log=(file)/tmp/spy.log). The spy.log file includes the name of the current thread (logTName=yes) and a timestamp on each line in the log (timestamp=yes).Using JDBC Data Sources
The SequeLink for JDBC driver implements the following JDBC features:
You can use DataDirect Spy to track JDBC calls made by a running application with any of these features. The com.ddtek.jdbcx.sequelink.datasource.SequeLinkDataSource class supports setting a semi-colon-separated list of DataDirect Spy attributes (see "DataDirect Spy™ Attributes").
See "Configuring JDBC Data Sources" for more information about configuring data sources.
Example on Windows:
The following example creates a JDBC data source for the SequeLink for JDBC driver, which enables DataDirect Spy.
... SequeLinkDataSource sds=new SequeLinkDataSource(): sds.setServerName("MyServer"); sds.setPortNumber(1234); sds.setSpyAttributes("log=(file)C:\tmp\spy.log;logIS=yes; logTName=yes"); Connection conn=sds.getConnection("scott","tiger"); ...Using this example, DataDirect Spy would load the SequeLink for JDBC driver and log all JDBC activity to the spy.log file located in the C:\temp directory (
log=(file)C:\temp\spy.log). In addition to regular JDBC activity, the spy.log file also logs activity on InputStream and Reader objects (logIS=yes). It also includes the name of the current thread (logTName=yes).NOTE: If coding a path on Windows to the log file in a Java string, the backslash character (\) must be preceded by the Java escape character, a backslash. For example: "log=(file)C:\\temp\\spy.log;logIS=yes;logTName=yes".
Example on Linux and UNIX:
The following example creates a JDBC data source for the SequeLink for JDBC driver, which enables DataDirect Spy.
... SequeLinkDataSource sds=new SequeLinkDataSource(): sds.setServerName("MyServer"); sds.setPortNumber(1234); sds.setSpyAttributes("log=(file)C:\tmp\spy.log;logIS=yes;logTName=yes"); Connection conn=sds.getConnection("TEST","secret"); ...Using this example, DataDirect Spy would load the SequeLink for JDBC driver and log all JDBC activity to the spy.log file located in the /tmp directory (
log=(file)/tmp/spy.log). The spy.log file includes the name of the current thread (logTName=yes).Using the DataDirect Spy™ URL
If you enable DataDirect Spy using a DataDirect Spy URL, you first must register the DataDirect Spy driver with the JDBC Driver Manager. Registering a driver tells the Driver Manager which driver to load. The DataDirect Spy driver name is com.ddtek.jdbc.SpyDriver.
For example, to load the DataDirect Spy driver using the standard Class.forName method, include the following code in your application or applet and call DriverManager.getConnection:
For complete information about registering drivers with the JDBC Driver Manager, see "Registering the JDBC Driver".
You can enable DataDirect Spy using a DataDirect Spy-specific URL that has the following format:
where:
original-url is the connection URL of the SequeLink for JDBC driver. For example, the following connection URL uses the SequeLink for JDBC driver:
key
=value is a semi-colon separated list of DataDirect Spy attributes (see "DataDirect Spy™ Attributes").Example on Windows:
The following example uses a DataDirect Spy URL to enable DataDirect Spy:
jdbc:spy:{jdbc:sequelink://QANT:4003;databaseName=Oracle; OSUser=qauser;OSPassword=null12};log=System.out; linelimit=72Using this example, DataDirect Spy would load the JDBC driver and log all JDBC activity to the Java output standard file, System.out (
log=System.out). The spy.log file logs a maximum of 72 characters on each line (linelimit=72).Example on Linux/UNIX:
The following example uses a DataDirect Spy URL to enable DataDirect Spy:
jdbc:spy:{jdbc:sequelink://QANT:4003; databaseName=Oracle;OSUser=qauser;OSPassword=null12}; log=System.out;linelimit=72Using this example, DataDirect Spy would load the JDBC driver and log all JDBC activity to the Java output standard file, System.out (
log=System.out). The spy.log file logs a maximum of 72 characters on each line (linelimit=72).